{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Horizon Graph\n",
    "-------------\n",
    "This example shows how to make a Horizon Graph with 2 layers. (See https://idl.cs.washington.edu/papers/horizon/ for more details on Horizon Graphs.)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import altair as alt\n",
    "alt.data_transformers.enable('json')\n",
    "from altair.expr import datum\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.DataFrame([\n",
    "      {\"x\": 1,  \"y\": 28}, {\"x\": 2,  \"y\": 55},\n",
    "      {\"x\": 3,  \"y\": 43}, {\"x\": 4,  \"y\": 91},\n",
    "      {\"x\": 5,  \"y\": 81}, {\"x\": 6,  \"y\": 53},\n",
    "      {\"x\": 7,  \"y\": 19}, {\"x\": 8,  \"y\": 87},\n",
    "      {\"x\": 9,  \"y\": 52}, {\"x\": 10, \"y\": 48},\n",
    "      {\"x\": 11, \"y\": 24}, {\"x\": 12, \"y\": 49},\n",
    "      {\"x\": 13, \"y\": 87}, {\"x\": 14, \"y\": 66},\n",
    "      {\"x\": 15, \"y\": 17}, {\"x\": 16, \"y\": 27},\n",
    "      {\"x\": 17, \"y\": 68}, {\"x\": 18, \"y\": 16},\n",
    "      {\"x\": 19, \"y\": 49}, {\"x\": 20, \"y\": 15}\n",
    "    ])\n",
    "\n",
    "area1 = alt.Chart(df).mark_area(\n",
    "    clip=True,\n",
    "    interpolate='monotone'\n",
    ").encode(\n",
    "    alt.X('x', scale=alt.Scale(zero=False, nice=False)),\n",
    "    alt.Y('y', scale=alt.Scale(domain=[0, 50]), axis=alt.Axis(title='y')),\n",
    "    opacity=alt.value(0.6)\n",
    ").properties(\n",
    "    width=500,\n",
    "    height=75\n",
    ")\n",
    "\n",
    "area2 = area1.encode(\n",
    "    alt.Y('ny:Q', scale=alt.Scale(domain=[0, 50]))\n",
    ").transform_calculate(\n",
    "    \"ny\", datum.y - 50\n",
    ")\n",
    "\n",
    "area1 + area2\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "env": {},
   "interrupt_mode": "signal",
   "language": "python",
   "metadata": {},
   "name": "python3"
  },
  "language": "python"
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
